// 管理用户数据相关
import { defineStore } from 'pinia'
import { ref } from 'vue'
import axiosInstance from '@/axios/index.js'

export const useStudentStore = defineStore('student', {
    state: () => ({
        studentInfo: ref({})
    }),
    actions: {
        getStudentInfo(studentId) {
            axiosInstance.get(`/student/studentInfo`, {params: {studentId}
            }).then(res => {
                this.studentInfo = res.data.data
            })
        },
        getStudentInfoByPhone(telephone) {
            axiosInstance.get(`/student/studentInfo/phone`, {params: {telephone}
            }).then(res => {
                this.studentInfo = res.data.data
            })
        },
        clearStudentInfo() {
            this.studentInfo = {}
        }
    },
    // 使用 pinia-plugin-persist 的 persist 选项
    persist: {
        enabled: true, // 开启持久化
        strategies: [
            {
                key: 'student', // 存储的 key，默认为 store 的 id
                storage: localStorage, // 或 sessionStorage
                paths: ['studentInfo'] // 需要持久化的 state 路径数组
            }
        ]
    }
})